﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;

namespace ORS.BLL
{
    public class SearchName
    {
        public string getUsername(string id)
        {
            string sqlstr = "select cname from tb_userlist where userid = '" + id + "' ";
            ORS.DAL.DBHelper db = new ORS.DAL.DBHelper();
            string username = db.GetRoleName(sqlstr).ToString().Trim();
            return username;
        }

        public string getPreReviewCount()
        {
            string countsqlstr ="select count(*) from tb_paperinfo where reviewstate = '0' or reviewstate = '1'";
            ORS.DAL.DBHelper countdb = new ORS.DAL.DBHelper();
            string reviewnum = countdb.GetRoleName(countsqlstr).ToString().Trim();
            return reviewnum;
        }

        public string getNoApprovCount(String userNam)
        {
            string countsqlstr = "select count(*) from tb_paperinfo where approvestate < 2 and authorid= '"+userNam+"'";
            ORS.DAL.DBHelper countdb = new ORS.DAL.DBHelper();
            string reviewnum = countdb.GetRoleName(countsqlstr).ToString().Trim();
            return reviewnum;
        }

        public DataTable getReviewDataSet()
        {
            string reviewsqlstr = "select tiltle,paperid,cname,name,submitdate,sublimitdate from tb_paperinfo inner join tb_userlist on tb_paperinfo.authorid=tb_userlist.userid inner join tb_interest on tb_paperinfo.interestid = tb_interest.interestid where reviewstate = '0' or reviewstate = '1'";
            ORS.DAL.DBHelper reviewdb = new ORS.DAL.DBHelper();
            DataSet reviewds = new DataSet();
            reviewds = reviewdb.getDateSet(reviewsqlstr);
            return reviewds.Tables[0];
        }

        public DataTable userSearchReviewDataSet(string seachObject)
        {
            string reviewsqlstr = "SELECT tb_reviewhistory.paperid, tb_paperinfo.tiltle, tb_userlist.cname, tb_paperinfo.submitdate, tb_reviewhistory.reviewstate, tb_reviewhistory.reviewdate, tb_reviewhistory.reviewcomm, tb_paperinfo.approvestate FROM tb_paperinfo INNER JOIN tb_reviewhistory ON tb_paperinfo.paperid = tb_reviewhistory.paperid INNER JOIN tb_userlist ON tb_paperinfo.authorid = tb_userlist.userid where tb_userlist.cname like '%" + seachObject + "%' ";
            ORS.DAL.DBHelper reviewdb = new ORS.DAL.DBHelper();
            DataSet reviewds = new DataSet();
            reviewds = reviewdb.getDateSet(reviewsqlstr);
            return reviewds.Tables[0];
        }

        public DataTable titleSearchReviewDataSet(string seachObject)
        {
            string reviewsqlstr = "SELECT tb_reviewhistory.paperid, tb_paperinfo.tiltle, tb_userlist.cname, tb_paperinfo.submitdate, tb_reviewhistory.reviewstate, tb_reviewhistory.reviewdate, tb_reviewhistory.reviewcomm, tb_paperinfo.approvestate FROM tb_paperinfo INNER JOIN tb_reviewhistory ON tb_paperinfo.paperid = tb_reviewhistory.paperid INNER JOIN tb_userlist ON tb_paperinfo.authorid = tb_userlist.userid where tb_paperinfo.tiltle like '%" + seachObject + "%' ";
            ORS.DAL.DBHelper reviewdb = new ORS.DAL.DBHelper();
            DataSet reviewds = new DataSet();
            reviewds = reviewdb.getDateSet(reviewsqlstr);
            return reviewds.Tables[0];
        }

        public DataTable interestSearchReviewDataSet(string seachObject)
        {
            string reviewsqlstr = "SELECT tb_reviewhistory.paperid, tb_paperinfo.tiltle, tb_userlist.cname, tb_paperinfo.submitdate, tb_reviewhistory.reviewstate, tb_reviewhistory.reviewdate, tb_reviewhistory.reviewcomm, tb_paperinfo.approvestate FROM tb_paperinfo INNER JOIN tb_reviewhistory ON tb_paperinfo.paperid = tb_reviewhistory.paperid INNER JOIN tb_userlist ON tb_paperinfo.authorid = tb_userlist.userid where tb_paperinfo.interestid = '" + seachObject + "'";
            ORS.DAL.DBHelper reviewdb = new ORS.DAL.DBHelper();
            DataSet reviewds = new DataSet();
            reviewds = reviewdb.getDateSet(reviewsqlstr);
            return reviewds.Tables[0];
        }
    }
}